package com.jht.pj.sys.service.impl;

import com.jht.pj.sys.dao.MemberDao;
import com.jht.pj.sys.pojo.Admin;
import com.jht.pj.sys.pojo.Member;
import com.jht.pj.sys.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;
/*用户登录*/
    @Override
    public String memberloginObject(String username, String password) {
        if("".equals(username)&&"".equals(password)){
            return "用户名和密码不能为空";
        }else if("".equals(username)){
            return "用户名不能为空";
        }else if("".equals(password)){
            return "密码不能为空";
        }
        String result=null;

        Member member=memberDao.memberlogin(username);
        try {
            if (password.equals(member.getPassword())) {
                result = "登录成功";
            } else if (password.equals(member.getPassword())) {
                result = "密码错误，请重新输入";
            }
        }catch (Exception e){
            result="用户名或密码不正确";
        }
        return result;
    }

    /*用户注册*/
    @Override
    public String memberlogonObject(String username, String password) {
        if("".equals(username)&&"".equals(password)){
            return "用户名和密码不能为空";
        }else if("".equals(username)){
            return "用户名不能为空";
        }else if("".equals(password)){
            return "密码不能为空";
        }

        String result2 = null;

        Member member=new Member();
        member.setUsername(username);
        member.setPassword(password);

        int rows=memberDao.memberlogon(member);
        System.out.println(rows);

        if(rows == 1){
            result2="注册ok";
        }
        return result2;
    }

    /*用户找回密码*/
    @Override
    public String memberfindObject(String name) {
        if("".equals(name)){
            return "名字不能为空";
        }
        String result03=null;

        String psw=memberDao.memberfind(name);
        if(psw==null){
            result03="没有这个名字";
        }else {
            result03=psw;
        }
        return result03;
    }

}









